package it.yuzuojian.com.controller;




import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

/**
 * @author yzj
 */
@Controller
@RequestMapping("/index")
public class IndexController {
    @PostMapping("/login")
    public String login(@RequestParam("ip") String ip , @RequestParam("port") String port, Model model){
        if(StringUtils.isEmpty(port)){
            model.addAttribute("path",ip);
        }else {
            model.addAttribute("path",ip+":"+port);
        }

        return "screen";
    }
    /*@ResponseBody
    @GetMapping("/run")
    public String run(HttpServletResponse response) throws IOException {
        ServletOutputStream servletOutputStream=null;
        try {

            servletOutputStream = response.getOutputStream();
            Robot robot = new Robot();


            robot.delay(1000);
            Dimension d = new Dimension(Toolkit.getDefaultToolkit().getScreenSize());
            int width = (int)d.getWidth();
            int height = (int)d.getHeight();
            BufferedImage image = robot.createScreenCapture(new Rectangle(0,0,width,height));
            //在内存中创建压缩图片的缓冲区
            BufferedImage tmpImg=new BufferedImage(width,height ,BufferedImage.TYPE_3BYTE_BGR);
            //在缓冲区按缩放后的大小绘制压缩图片
            tmpImg.getGraphics().drawImage(image.getScaledInstance(width,height,Image.SCALE_SMOOTH), 0, 0, null);
            //设置图片质量，
            JPEGEncodeParam jep =   JPEGCodec.getDefaultJPEGEncodeParam(tmpImg);
            jep.setQuality(0.0001f, true);
                //ByteArrayOutputStream out = new ByteArrayOutputStream();
            JPEGImageEncoder encoder = new JPEGImageEncoderImpl(servletOutputStream);
            encoder.encode(image);
            encoder.setJPEGEncodeParam(jep);

        } catch (IOException | AWTException e) {
            e.printStackTrace();
        }finally {
            servletOutputStream.close();
        }

        return "screen";
    }*/
}
